package easycmd

import (
	"flag"
)

// Run 命令行程序启动
// 注意：启动前要确保所有命令均已注册
func Run() {
	ctx.run()
}

// GetArgVal 根据EasyCmd和参数名获取值
func GetArgVal[T int | int64 | uint | uint64 | float64 | string | bool](c *Command, argName string) T {
	val := c.GetArgVal(argName)
	t := val.(*T)
	return *t
}

// Build 构建 Command
func Build(cmdName, cmdDesc string) *Command {
	if cmdName == "" {
		panic("command name must be not blank")
	}

	if cmdDesc == "" {
		panic("command usage must be not blank")
	}

	return &Command{
		name:      cmdName,
		desc:      cmdDesc,
		f:         flag.NewFlagSet(cmdName, flag.ExitOnError),
		parsedMap: make(map[string]any),
	}
}
